package org.hqs.admin.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.hqs.admin.pojo.Admin;

import java.util.List;

public interface AdminMapper {

    @Select("select * from tb_admin where id = #{id}")
    Admin findById(Long id);

    @Select("SELECT * FROM tb_admin")
    List<Admin> findAllAdmins();

    @Insert("insert into tb_admin(name, sex, birth, password) values(#{name}, #{sex}, #{birth}, #{password})")
    int insertAdmin(Admin admin);

    @Update({
            "<script>",
            "update tb_admin",
            "<set>",
            "<if test='name != null'>name = #{name},</if>",
            "<if test='sex != null'>sex = #{sex},</if>",
            "<if test='birth != null'>birth = #{birth},</if>",
            "<if test='password != null'>password = #{password}</if>",
            "</set>",
            "where id = #{id}",
            "</script>"
    })
    int updateAdmin(Admin admin);

    @Delete("delete from tb_admin where id = #{id}")
    int deleteAdmin(Long id);
}
